package com.education.platform.management.controller.course;

import com.education.platform.common.enums.DicTypeEnum;
import com.education.platform.common.exception.BusinessException;
import com.education.platform.common.util.BeanUtil;
import com.education.platform.dao.entity.CoursewareDO;
import com.education.platform.dao.entity.SysDictionaryDO;
import com.education.platform.management.service.CoursewareService;
import com.education.platform.management.service.SysDictionaryService;
import com.education.platform.management.vo.request.CoursewareQueryVO;
import com.education.platform.management.vo.request.CoursewareUpdateVO;
import com.education.platform.management.vo.response.CoursewarePageInfoVO;
import com.education.platform.management.vo.response.CoursewareResponseVO;
import com.education.platform.management.vo.response.SysDictionaryResponseVO;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
* describe: 课件
* @author : tomato
* @date: 2020-06-29 10:28:07.450
**/
@RestController
@Api("课件")
@RequestMapping("courseware")
@Validated
public class CoursewareController {

    private static final Logger LOGGER = LoggerFactory.getLogger(CoursewareController.class);

	@Autowired
    private CoursewareService coursewareService;
    @Autowired
    private SysDictionaryService sysDictionaryService;



    /**
     * 删除课件
     * @param
     * @return
     */
    @ApiOperation(value = "删除多个视频")
    @DeleteMapping("delete")
    public void delete(@RequestBody List<Integer> ids) {
        if(CollectionUtils.isEmpty(ids)){
            throw new BusinessException("数据为空");
        }
        coursewareService.deleteByIds(ids);
    }

    @ApiOperation(value = "获取课件类型")
    @PostMapping("selectTypes")
    public List<SysDictionaryResponseVO> selectTags() {
        List<String> typeCodes = Arrays.asList(DicTypeEnum.SELECTION_TYPE.getValue());
        List<SysDictionaryDO> dictionaryDTOS = sysDictionaryService.getListByDicTypeCodeList(typeCodes);
        List<SysDictionaryResponseVO> result = new ArrayList<>();
        result.addAll(BeanUtil.convert(dictionaryDTOS,SysDictionaryResponseVO.class));
        return result;
    }

}
